﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using QLXuongCNTT.Object;
using QLXuongCNTT.DataLayers;

namespace QLXuongCNTT.ControlLayers
{
    class ctrPhieunhap
    {
        dtlPhieunhap dtPN, dtPN_nam;
        DataTable tbPN;
        objPhieunhap phieunhap;

        internal objPhieunhap Phieunhap
        {
            get { return phieunhap; }
            set { phieunhap = value; }
        }

        string error;

        public string Error
        {
            get { return error; }
            set { error = value; }
        }
        public ctrPhieunhap()
        {
            dtPN = new dtlPhieunhap();
            phieunhap = new objPhieunhap();
            dtPN_nam = new dtlPhieunhap();
            error = "";
        }
        public void getPhieunhap(TreeView trv)
        {
            tbPN = dtPN.getPN_nam();
            int sd = tbPN.Rows.Count;
            foreach (DataRow r in  tbPN.Rows)
            {
                //DataRow r = tbPN.Rows[i];
                TreeNode node_nam=new TreeNode();
                string nam =r[0].ToString();
                node_nam.Text = "Năm "+ nam;
                node_nam.ImageIndex = 0;
                DataTable pn = dtPN_nam.getPN(int.Parse(nam));
                foreach(DataRow rr in pn.Rows)
                {
                    string sopn = rr[0].ToString();
                    string tenpn = rr[4].ToString();
                    TreeNode node_pn = new TreeNode();
                    node_pn.Text = sopn;
                    node_pn.Tag = sopn;
                    node_nam.Nodes.Add(node_pn);
                    node_pn.ImageIndex = 1;
                }
                //add nam
                trv.Nodes.Add(node_nam);
            }
            error = dtPN.Error;
           
        }
        public void insertPhieunhap()
        {
            dtPN.insertPN(Phieunhap);
            if (dtPN.Error != "")
                error = dtPN.Error;
        }
        public DataTable THONGTIN_PN()
        {
            
            return dtPN.Get_PHIEUNHAP(phieunhap.Sophieu);
        }
        public void DeletePN()
        {
            dtPN.DeletePN(phieunhap.Sophieu);
            error = dtPN.Error;
        }
        public void UpdatePN()
        {
            dtPN.UpdatePN(phieunhap);
            error = dtPN.Error;
        }

    }
}
